@page "/DataPermission/ObjectPermissions"



@attribute [Authorize(DataPermissionPermissions.ObjectPermissions.Default)]
@using global::JS.Abp.DataPermission.ObjectPermissions
@using global::JS.Abp.DataPermission.Localization
@using global::JS.Abp.DataPermission.Shared
@using Microsoft.AspNetCore.Authorization
@using Microsoft.Extensions.Localization
@using Microsoft.AspNetCore.Components.Web
@using Blazorise
@using Blazorise.Components
@using Blazorise.DataGrid
@using Volo.Abp.BlazoriseUI
@using Volo.Abp.BlazoriseUI.Components
@using Volo.Abp.ObjectMapping
@using Volo.Abp.AspNetCore.Components.Messages
@using Volo.Abp.AspNetCore.Components.Web.Theming.Layout
@using global::JS.Abp.DataPermission.Permissions
@using Microsoft.AspNetCore.Components
@using Volo.Abp.AspNetCore.Components.Web
@using Volo.Abp.Http.Client
@inherits DataPermissionComponentBase
@inject IObjectPermissionsAppService ObjectPermissionsAppService
@inject IUiMessageService UiMessageService
@inject IRemoteServiceConfigurationProvider RemoteServiceConfigurationProvider
@inject NavigationManager NavigationManager

@* ************************* PAGE HEADER ************************* *@
<PageHeader Title="@L["ObjectPermissions"]" BreadcrumbItems="BreadcrumbItems" Toolbar="Toolbar">

</PageHeader>

@* ************************* SEARCH ************************* *@
<Card>
    <CardBody>
        <Form id="ObjectPermissionSearchForm" class="mb-3">
            <Addons>
                <Addon AddonType="AddonType.Body">
                    <TextEdit @bind-Text="@Filter.FilterText"
                              Autofocus="true"
                              Placeholder="@L["Search"]">
                    </TextEdit>
                </Addon>
                <Addon AddonType="AddonType.End">
                    <SubmitButton Form="ObjectPermissionSearchForm" Clicked="GetObjectPermissionsAsync">
                        <Icon Name="IconName.Search" Class="me-1"></Icon>@L["Search"]
                    </SubmitButton>
                </Addon>
            </Addons>
        </Form>
    </CardBody>
</Card>

@* ************************* DATA GRID ************************* *@
<Card>
    <CardBody>
        <DataGrid TItem="ObjectPermissionDto"
                  Data="ObjectPermissionList"
                  ReadData="OnDataGridReadAsync"
                  TotalItems="TotalCount"
                  ShowPager="true"
                  Responsive="true"
                  PageSize="PageSize">
            <DataGridColumns>
                <DataGridEntityActionsColumn TItem="ObjectPermissionDto" @ref="@EntityActionsColumn">
                    <DisplayTemplate>
                        <EntityActions TItem="ObjectPermissionDto" EntityActionsColumn="@EntityActionsColumn">
                            <EntityAction TItem="ObjectPermissionDto"
                                          Visible="@CanEditObjectPermission"
                                          Clicked="async () => await OpenObjectPermissionDetailAsync(context)"
                                          Text="@L["EditDetails"]">
                            </EntityAction>
                            <EntityAction TItem="ObjectPermissionDto"
                                          Visible="@CanEditObjectPermission"
                                          Clicked="async () => await OpenEditObjectPermissionModalAsync(context)"
                                          Text="@L["Edit"]">
                            </EntityAction>
                            <EntityAction TItem="ObjectPermissionDto"
                                          Visible="@CanDeleteObjectPermission"
                                          Clicked="() => DeleteObjectPermissionAsync(context)"
                                          ConfirmationMessage="@(() => L["DeleteConfirmationMessage"])"
                                          Text="@L["Delete"]">
                            </EntityAction>
                        </EntityActions>
                    </DisplayTemplate>
                </DataGridEntityActionsColumn>
               
              <DataGridColumn TItem="ObjectPermissionDto"
                      Field="ObjectName"
                      Caption="@L["ObjectName"]">
              </DataGridColumn>

              <DataGridColumn TItem="ObjectPermissionDto"
                      Field="Description"
                      Caption="@L["Description"]">
              </DataGridColumn>

            </DataGridColumns>
        </DataGrid>
    </CardBody>
</Card>

@* ************************* CREATE MODAL ************************* *@
<Modal @ref="CreateObjectPermissionModal" Closing="@CreateObjectPermissionModal.CancelClosingModalWhenFocusLost">
    <ModalContent Centered="true">
        <Form id="CreateObjectPermissionForm">
            <ModalHeader>
                <ModalTitle>@L["NewObjectPermission"]</ModalTitle>
                <CloseButton Clicked="CloseCreateObjectPermissionModalAsync" />
            </ModalHeader>
            <ModalBody>
                <Validations @ref="@NewObjectPermissionValidations"
                            Mode="ValidationMode.Auto"
                            Model="@NewObjectPermission"
                            ValidateOnLoad="false">
                     
                    
                    <Validation>
                        <Field>
                            <FieldLabel>@L["ObjectName"] *</FieldLabel>
                            <TextEdit @bind-Text="@NewObjectPermission.ObjectName" MaxLength="ObjectPermissionConsts.ObjectNameMaxLength">
                                <Feedback>
                                    <ValidationError />
                                </Feedback>
                            </TextEdit>
                        </Field>
                    </Validation>


                    <Validation>
                        <Field>
                            <FieldLabel>@L["Description"]</FieldLabel>
                            <TextEdit @bind-Text="@NewObjectPermission.Description" >
                                <Feedback>
                                    <ValidationError />
                                </Feedback>
                            </TextEdit>
                        </Field>
                    </Validation>


                    
                    
                </Validations>
            </ModalBody>
            <ModalFooter>
                <Button Color="Color.Secondary"
                        Clicked="CloseCreateObjectPermissionModalAsync">
                    @L["Cancel"]
                </Button>
                <SubmitButton Form="CreateObjectPermissionForm" Clicked="CreateObjectPermissionAsync" />
            </ModalFooter>
        </Form>
    </ModalContent>
</Modal>

@* ************************* EDIT MODAL ************************* *@
<Modal @ref="EditObjectPermissionModal" Closing="@EditObjectPermissionModal.CancelClosingModalWhenFocusLost">
    <ModalContent Centered="true">
        <Form id="EditObjectPermissionForm">
            <ModalHeader>
                <ModalTitle>@L["Update"]</ModalTitle>
                <CloseButton Clicked="CloseEditObjectPermissionModalAsync" />
            </ModalHeader>
            <ModalBody>
                <Validations @ref="@EditingObjectPermissionValidations"
                            Mode="ValidationMode.Auto"
                            Model="@EditingObjectPermission"
                            ValidateOnLoad="false">
                     
                    
                    <Validation>
                        <Field>
                            <FieldLabel>@L["ObjectName"] *</FieldLabel>
                            <TextEdit @bind-Text="@EditingObjectPermission.ObjectName" ReadOnly="true" MaxLength="ObjectPermissionConsts.ObjectNameMaxLength">
                                <Feedback>
                                    <ValidationError />
                                </Feedback>
                            </TextEdit>
                        </Field>
                    </Validation>


                    <Validation>
                        <Field>
                            <FieldLabel>@L["Description"]</FieldLabel>
                            <TextEdit @bind-Text="@EditingObjectPermission.Description" >
                                <Feedback>
                                    <ValidationError />
                                </Feedback>
                            </TextEdit>
                        </Field>
                    </Validation>


                    
                    
                </Validations>
            </ModalBody>
            <ModalFooter>
                <Button Color="Color.Secondary"
                        Clicked="CloseEditObjectPermissionModalAsync">
                    @L["Cancel"]
                </Button>
                <SubmitButton Form="CreateObjectPermissionForm" Clicked="UpdateObjectPermissionAsync" />
            </ModalFooter>
        </Form>
    </ModalContent>
</Modal>
